/*
** assert.c for Kernel in /home/icecrime/Kernel
** 
** Made by U-ICE\icecrime
** Login   <icecrime@epita.fr>
** 
** Started on  Tue Oct 17 18:20:20 2006 U-ICE\icecrime
** Last update Thu Oct 19 17:37:16 2006 icecrime
*/

#include "bochs.h"
#include "system.h"
#include "assert.h"
#include "display.h"

#define	ASSERT_ATTRIB	(COLOR(RED, WHITE))

static void	__assert_puts(const char *str, char attrib)
{
  putsp(str, attrib);
  bochs_puts(str);
}

static void	__assert_putnumber(const int number, char attrib)
{
  putnumberp(number, attrib);
  bochs_putnumber(number);
}

void		assert_failure(const char *exp,
			       const char *file, int line, char *msg)
{
  __assert_puts("\n\n!! Assertion failed\n", ASSERT_ATTRIB);
  __assert_puts("  At :      ", ASSERT_ATTRIB);
  __assert_puts(file, ASSERT_ATTRIB);
  __assert_puts(":", ASSERT_ATTRIB);
  __assert_putnumber(line, ASSERT_ATTRIB);
  __assert_puts("\n  Test :    ", ASSERT_ATTRIB);
  __assert_puts(exp, ASSERT_ATTRIB);
  if (msg != NULL)
    {
      __assert_puts("\n  Message : ", ASSERT_ATTRIB);
      __assert_puts(msg, ASSERT_ATTRIB);
      __assert_puts("\n", ASSERT_ATTRIB);
    }
  while (1)
    asm("hlt;");
}
